﻿Public Class frmBussy
    Public ballowclose As Boolean = False
    Public Sub CloseForm()
        ballowclose = True
        Me.Close()
    End Sub
    Delegate Sub setM(Message As String)
    Public Sub setMessage(Message As String)
        Try
            SetText("FAHWatch7" & Environment.NewLine & Environment.NewLine & Message)
        Catch ex As Exception
            WriteError(ex.Message, Err)
        End Try
    End Sub
    Private Sub SetText(ByVal Message As String)
        Try
            If Label1.InvokeRequired Then
                Dim d As New setM(AddressOf SetText)
                Me.Invoke(d, New Object() {Message})
            Else
                Label1.Text = Message
            End If
            Application.DoEvents()
        Catch ex As Exception
            WriteError(ex.Message, Err)
        End Try
    End Sub
    Private Sub frmBussy_FormClosing(sender As Object, e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        Try
            If Not ballowclose Then
                e.Cancel = True
                Me.WindowState = FormWindowState.Minimized
            End If
        Catch ex As Exception
            WriteError(ex.Message, Err)
        End Try
    End Sub

    Public Sub New(BorderStyle As FormBorderStyle, Optional MdiParent As Form = Nothing)
        ' This call is required by the designer.
        InitializeComponent()
        ' Add any initialization after the InitializeComponent() call.
        Try
            Me.FormBorderStyle = BorderStyle
            If BorderStyle = Windows.Forms.FormBorderStyle.None Then
                With Me
                    .ShowInTaskbar = False
                    .ShowIcon = False
                    .StartPosition = FormStartPosition.CenterParent
                    .MdiParent = MdiParent
                End With
            Else
                If IsNothing(MdiParent) Then
                    With Me
                        .StartPosition = FormStartPosition.CenterScreen
                        .ControlBox = True
                        .UseWaitCursor = True
                        .ShowIcon = True
                        .ShowInTaskbar = True
                    End With
                Else
                    With Me
                        .ShowInTaskbar = False
                        .ShowIcon = False
                        .StartPosition = FormStartPosition.CenterParent
                        .MdiParent = MdiParent
                        .TopMost = True
                    End With
                End If

            End If
        Catch ex As Exception
            WriteError(ex.Message, Err)
        End Try
    End Sub
End Class